﻿--HEADER Rename and update  iComply.SuspiciousActivity.IsActive Column

declare @constraint_name sysname, @sql nvarchar(max)


select @constraint_name = dobj.name  
from sys.columns col 
    left outer join sys.objects dobj 
        on dobj.object_id = col.default_object_id and dobj.type = 'D' 
where col.object_id = object_id(N'iComply.SuspiciousActivity') 
and col.name = 'IsActive'
and dobj.name is not null

set @sql = N'alter table iComply.SuspiciousActivity drop constraint ' + @constraint_name
exec sp_executesql @sql
--EXEC sp_rename 'iComply.SuspiciousActivity.Status', 'IsActive', 'COLUMN';
alter table iComply.SuspiciousActivity add [Status] tinyint null
GO
update iComply.SuspiciousActivity set [Status] = IsActive
GO
alter table iComply.SuspiciousActivity alter column [Status] tinyint not null
alter table iComply.SuspiciousActivity drop column IsActive
